package com.mijie.homi.inteceptor;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.mijie.core.Status;
import com.mijie.homi.common.constant.HomiStatusCode;
import com.mijie.homi.util.ServerHelper;
import com.mijie.util.IOUtil;


public class ExceptionHandler implements HandlerExceptionResolver {

	private Logger logger = Logger.getLogger(ExceptionHandler.class);
	
	
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		Integer userId = ServerHelper.getUserId(request);
		logger.error("[user:"+userId+"]"+ex.getMessage(), ex);
		Status status = new Status(request,response);
		status.setCode(HomiStatusCode.API_EXCEPTION);
		status.write();
		return null;
	}

}
